package com.conversationboard.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import com.conversationboard.database.Database;
import com.conversationboard.database.Queries;

public class SiteInfo {

    public static List<String> getRecentlyRegisteredUsers() throws SQLException {

        Connection connection = null;
        List<String> users = new LinkedList<String>();

        try {
            connection = Database.getConnection();

            PreparedStatement statement = connection.prepareStatement(Queries.GET_RECENTLY_REGISTERED_USERS);
            statement.execute();

            ResultSet resultSet = statement.getResultSet();

            while (resultSet.next()) {
                users.add(resultSet.getString("loginid"));
            }

            statement.close();

            return users;

        } finally {
            Database.close(connection);
        }

    }


    public static int getNumberOfRegisteredUsers() throws SQLException {

        Connection connection = null;
        int count = 0;

        try {
            connection = Database.getConnection();

            PreparedStatement statement = connection.prepareStatement(Queries.GET_NUMBER_OF_REGISTERED_USERS);
            statement.execute();

            ResultSet resultSet = statement.getResultSet();

            while (resultSet.next()) {
                count = resultSet.getInt("count");
            }

            statement.close();

            return count;

        } finally {
            Database.close(connection);
        }

    }

}
